// pages/addinfo/addinfo.js
const request=require('../../util/request.js')
const instruct = require('../../util/tspl')
import bleDisNetwork from '../../util/bleDisNetwork'
Page({

  /**
   * 页面的初始数据
   */
  data: {
   
    list:[],
    page: 1,//页码
    limit: 5,//每页数量
    type:0,//可不传参数
    keyword:"",//可不传参数
    add_time:"",//可不传参数
    p_no:"",//项目号
    count: 0,
    projectbody:[],//项目主体信息
    datastatus:2,//查看 2全部/1以完善/0未完成 
    datafind:"",//搜索关键字
    date:"",
    mindate:Math.round((new Date() - 365*86400*1000)),
    findtime:"",//时间范围查找
    __returnParams:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      __returnParams:false,

    })
    this.data.p_no = options.p_no
    this.data.page = 1
    this.getList()

  },

  onReachBottom() {
    console.log('sandbkas')
    if(this.data.flag){
      this.setData({
        flag:false
      })
      this.getList(); // 疯狂的请求的方法
    }
  },
  
  getList(search="",date="") {
    var that = this;
    var params = {
      page: that.data.page,//当前页码1
      limit: that.data.limit,
      keyword:that.data.datafind,//关键字
      add_time:this.data.findtime,
    }
    request.requestGet('fruit/get_plan', params, "加载中",function (res) {
      if (res.status === 200) {
        let list = that.data.plans
        res.data.plans.map((item) =>{
          return item.t = false;
        })
        if (that.data.page == 1) {
          list = []
        }
        list = [...list, ...res.data.plans]
        if (list.length < res.data.count ){
          that.setData({
            page: that.data.page + 1,
            flag:true
          })
        } else {
          that.setData({
            flag:false
          })
        }
        that.setData({
          projectbody: list,
          count: res.data.count
        })
      }
      }, function (res) {
        console.log(res,"请求失败")
      },
    )


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  submit(event){
  },
  bindKeyInputVant(event){
    let valueName = event.target.dataset.variable;
    let name = `formData.${valueName}`;
    this.setData({
      [valueName]:event.detail
    });
  },
  onDisplay() {
    this.setData({ show: true });
  },
  onClose() {
    this.setData({ show: false });
  },
  formatDate(date) {
    date = new Date(date);
    return `${date.getFullYear()}-${date.getMonth()+1}-${date.getDate()}`;
  },
  onConfirm(event) {
    this.data.page = 1
    this.setData({
      show: false,
      date: this.formatDate(event.detail[0])+' - '+this.formatDate(event.detail[1]),
      findtime : this.formatDate(event.detail[0])+' - '+this.formatDate(event.detail[1])
    });
    this.getList("",this.data.date)
  },

  onSearch(e){
    this.setData({
      flag:true
    })
    this.data.page = 1
    this.data.datafind = e.detail
    wx.pageScrollTo({
      scrollTop: 0,
      duration: 0
    })
    this.getList(e.detail)
  },
  // onReachBottom() {
  //   if(this.data.flag){
  //     this.setData({
  //       flag:false
  //     })
  //     this.getList(); // 疯狂的请求的方法
  //   }
  // },

  setrem(e){
    console.log(e,"eee")
    wx.navigateTo({
      url: `/pages/pic_no_rember/pic_no_rember?FInterID=${e.currentTarget.dataset.index}&fbillno=${e.currentTarget.dataset.fbillno}`,
    })
  },

  toindex(e){
    wx.navigateTo({
      url: `/pages/index/index?fid=${e.currentTarget.dataset.index}`,
    })
  },

  get_plan_info(e){
    let fid = e.currentTarget.dataset.index
    wx.navigateTo({ url: `/pages/get_plan_info/get_plan_info?fid=${fid}` })
  }
})